import Mock from 'mockjs'
import { List } from '../mockServeData/account.js'
export default {
    getMenu: config => {
        const { username, password } = JSON.parse(config.body)
        // 先判断用户是否存在
        // 判断账号和密码是否对应
        for (let i = 0; i < List.length; i++) {
            if (username === 'admin' && password === 'admin') {
                alert('欢迎您！超级管理员：admin')
                return {
                    code: 20000,
                    username: username,
                    data: {
                        menu: [
                            {
                                path: '/home',
                                name: 'home',
                                label: '首页',
                                icon: 's-home',
                                url: 'HomeView.vue'
                            },
                            {
                                path: '/mall',
                                name: 'mall',
                                label: '订单管理',
                                icon: 'edit-outline',
                                url: 'MallView.vue'
                            },
                            {
                                path: '/user',
                                name: 'user',
                                label: '用户管理',
                                icon: 'user',
                                url: 'UserView.vue'
                            },
                            {
                                path: '/account',
                                name: 'account',
                                label: '账号管理',
                                icon: 'key',
                                url: 'AccountView.vue'
                            },
                            {
                                label: '商户管理',
                                icon: 'star-off',
                                children: [
                                    {
                                        path: '/goods',
                                        name: 'goods',
                                        label: '商品管理',
                                        icon: 'cherry',
                                        url: 'GoodsView.vue'
                                    },
                                    {
                                        path: '/shop',
                                        name: 'shop',
                                        label: '店铺管理',
                                        icon: 's-shop',
                                        url: 'ShopView.vue'
                                    }
                                ]
                            }],
                    }
                }
            }
            else if (username === List[i].username && password === List[i].password && List[i].type === true && List[i].limit === '超级管理员') {
                alert('欢迎您！超级管理员：' + List[i].username)
                return {
                    code: 20000,
                    username: username,
                    data: {
                        menu: [
                            {
                                path: '/home',
                                name: 'home',
                                label: '首页',
                                icon: 's-home',
                                url: 'HomeView.vue'
                            },
                            {
                                path: '/mall',
                                name: 'mall',
                                label: '订单管理',
                                icon: 'edit-outline',
                                url: 'MallView.vue'
                            },
                            {
                                path: '/user',
                                name: 'user',
                                label: '用户管理',
                                icon: 'user',
                                url: 'UserView.vue'
                            },
                            {
                                path: '/account',
                                name: 'account',
                                label: '账号管理',
                                icon: 'key',
                                url: 'AccountView.vue'
                            },
                            {
                                label: '商户管理',
                                icon: 'star-off',
                                children: [
                                    {
                                        path: '/goods',
                                        name: 'goods',
                                        label: '商品管理',
                                        icon: 'cherry',
                                        url: 'GoodsView.vue'
                                    },
                                    {
                                        path: '/shop',
                                        name: 'shop',
                                        label: '店铺管理',
                                        icon: 's-shop',
                                        url: 'ShopView.vue'
                                    }
                                ]
                            }
                        ],
                        token: Mock.Random.guid(),
                        message: '获取成功'
                    }
                }
            }
            else if (username === List[i].username && password === List[i].password && List[i].type === true && List[i].limit === '管理员') {
                alert('欢迎您！管理员：' + List[i].username)
                return {
                    code: 20000,
                    username: username,
                    data: {
                        menu: [
                            {
                                path: '/home',
                                name: 'home',
                                label: '首页',
                                icon: 's-home',
                                url: 'HomeView.vue'
                            },
                            {
                                path: '/mall',
                                name: 'mall',
                                label: '订单管理',
                                icon: 'edit-outline',
                                url: 'MallView.vue'
                            },
                            {
                                path: '/user',
                                name: 'user',
                                label: '用户管理',
                                icon: 'user',
                                url: 'UserView.vue'
                            },
                            {
                                label: '商户管理',
                                icon: 'star-off',
                                children: [
                                    {
                                        path: '/goods',
                                        name: 'goods',
                                        label: '商品管理',
                                        icon: 'cherry',
                                        url: 'GoodsView.vue'
                                    },
                                    {
                                        path: '/shop',
                                        name: 'shop',
                                        label: '店铺管理',
                                        icon: 's-shop',
                                        url: 'ShopView.vue'
                                    }
                                ]
                            }
                        ],
                        token: Mock.Random.guid(),
                        message: '获取成功'
                    }
                }
            }
            else if (username === List[i].username && password === List[i].password && List[i].type === true && List[i].limit === '游客') {
                alert('欢迎您！游客：' + List[i].username)
                return {
                    code: 20000,
                    username: username,
                    data: {
                        menu: [
                            {
                                path: '/home',
                                name: 'home',
                                label: '首页',
                                icon: 's-home',
                                url: 'HomeView.vue'
                            }
                        ],
                        token: Mock.Random.guid(),
                        message: '获取成功'
                    }
                }
            }
        }
        return {
            code: -999,
            data: {
                message: '密码错误'
            }
        }
    }

}
